define('PageInit', [
  'fastclick',
  'VConsole',
  'env'
], function (fastclick, VConsole) {
  fastclick.attach(document.body);
  _initConsole();

  function _initConsole() {
    if (IS_DEBUG) {
      new VConsole();
    }
    if (!IS_DEBUG) {
      console.log = () => {}
      console.debug = () => {}
    }

  }

  function _pushBackHistory() {
    var state = window.history.state;
    if (state == null) {
      state = {
        title: document.title,
        url: "#"
      };
    } else {
      state.url = "#"
      state.title = document.title
    }
    window.history.pushState(state, document.title, "#");
  }

  function setHistoryCacheData(data) {
    var state = window.history.state;
    if (state == null) {
      state = {
        cacheData: data
      };
    } else {
      state.bundleData = data
    }
    window.history.replaceState(state, document.title);
  }

  function getHistoryCacheData() {
    var state = window.history.state;
    if (state) {
      return state.cacheData
    } else {
      return null;
    }
  }

  function back(callback) {
    _pushBackHistory();
    window.addEventListener("popstate", function (e) {
      callback(e);
      _pushHistory();
    }, false);
  }
  return {
    back: back,
    setHistoryCacheData: setHistoryCacheData,
    getHistoryCacheData: getHistoryCacheData
  }
});